import { IdManager } from "../../utils/util";
import { CanvasContext, } from "./designType";
import { Dimension } from "./Dimension";
import { Point } from "./Point";
import { Shape } from "./Shape";

export class Glass {
  public id: string;
  public dimension?: Dimension; 
  public glassNumber?: number;
  public shape?: Shape;  
  constructor() {
    this.id = IdManager.getNextId("glass");
  }

  // 
  setShape(shape: Shape) {
    this.shape = shape;
  }
  setStartPoint(startPoint:Point) {
    const shape = new Shape();
    shape.setStartPoint(startPoint);
    this.setShape(shape);
  }
  addGlass(
    edgeWidth:number,
    pressStripWidth:number,
    width:number,
    height:number
    ) {
    const glassPoint = new Point(
      edgeWidth - pressStripWidth,
      edgeWidth - pressStripWidth, 'rect',
    {
      width:width-edgeWidth* 2 + pressStripWidth*2,
      height:height-edgeWidth* 2 + pressStripWidth*2,
      fillColor: "rgba(173, 216, 230, 0.3)",
    })

    const pressStripLeft = new  Point(
      edgeWidth - pressStripWidth,
      edgeWidth,
       'rect',
    {
      width:pressStripWidth,
      height:height-edgeWidth*2,
      strokeColor: "rgba(30, 30, 30, 1)",
      fillColor: "rgba(192, 192, 192, 1)",
      lineWidth: 1,
    });
    const pressStripTop = new  Point(
      edgeWidth - pressStripWidth,
      edgeWidth - pressStripWidth, 'rect',
    {
      width:width-edgeWidth * 2 +pressStripWidth*2 ,
      height:pressStripWidth,
      strokeColor: "rgba(30, 30, 30, 1)",
      fillColor: "rgba(192, 192, 192, 1)",
      lineWidth: 1,
    });
    const pressStripRight = new  Point(
      width - edgeWidth,
      edgeWidth,
      'rect',
    {
      width:pressStripWidth,
      height:height-edgeWidth*2,
      strokeColor: "rgba(30, 30, 30, 1)",
      fillColor: "rgba(192, 192, 192, 1)",
      lineWidth: 1,
    });
    const pressStripBottom = new  Point(
      edgeWidth - pressStripWidth,
      height - edgeWidth,
       'rect',
    {
      width:width-edgeWidth*2 + pressStripWidth*2,
      height:pressStripWidth,
      strokeColor: "rgba(30, 30, 30, 1)",
      fillColor: "rgba(192, 192, 192, 1)",
      lineWidth: 1,
    });
    const pressAndGlassPoints: Point[]= [glassPoint, pressStripLeft, pressStripTop, pressStripRight, pressStripBottom];
    if(this.shape) {
      this.shape.pushPoints(pressAndGlassPoints);
    }

  }
  draw(ctx: CanvasContext): void {
    if(this.shape)
    this.shape.draw(ctx);
  }
}
